package com.threefish.common.vo;

import lombok.Data;

import java.io.Serializable;
import java.text.MessageFormat;

/**
 * @author 黄川 huchuc@vip.qq.com
 * @date: 2018/9/10
 */
@Data
public class ResultVO<T> implements Serializable {
    /**
     * 是否成功
     */
    private Boolean ok;
    /**
     * 错误消息提示
     */
    private String msg;
    /**
     * 错误地址
     */
    private String url;
    /**
     * 返回的数据内容
     */
    private T data;
    /**
     * http状态 500 404 200
     */
    private Integer status;

    public ResultVO() {
        this.ok = false;
        this.msg = "";
        this.status = 200;
    }

    public ResultVO(boolean ok, String msg) {
        this.msg = msg;
        this.ok = ok;
    }

    public ResultVO(boolean ok, String msg, T data) {
        this.ok = ok;
        this.msg = msg;
        this.data = data;
    }

    public static ResultVO sucess() {
        return new ResultVO(true, "");
    }

    public static ResultVO sucess(Object data) {
        ResultVO result = new ResultVO(true, "");
        result.setData(data);
        return result;
    }

    public static ResultVO sucessMsg(String msg) {
        ResultVO result = new ResultVO(true, msg);
        return result;
    }

    public static ResultVO sucess(Object data, String msg) {
        ResultVO result = new ResultVO(true, msg);
        result.setData(data);
        return result;
    }

    public static ResultVO error(String msg) {
        ResultVO result = new ResultVO(false, msg);
        return result;
    }

    public static ResultVO errorf(String msg, Object... params) {
        ResultVO result = new ResultVO(false, MessageFormat.format(msg, params));
        return result;
    }

}
